In [2]:
# This notebook creates a matrix for the electricity demand from the from the European Commission's Joint Research Centre’s EU Energy Atlas.
# Each plane of the matrix is dedicated for one demand sector.
# The values are in MWh
In [1]:
import rasterio
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
In [2]:
from IPython.core.display import display, HTML
display(HTML("<style>.output_scroll { height: 500px !important; }</style>"))
/var/folders/dq/9f7l1n4s0w5dyky898r6tbzh0000gn/T/ipykernel_62436/2030294557.py:1: DeprecationWarning: Importing display from IPython.core.display is deprecated since IPython 7.14, please import from IPython display from IPython.core.display import display, HTML
In [3]:
file_path_industry = "/Users/kobabendiks/Desktop/UNI/Bachelor Thesis/Datasets/Demand/industry_electricity_demand_2019.tif"
file_path_others = "/Users/kobabendiks/Desktop/UNI/Bachelor Thesis/Datasets/Demand/othersectors_electricity_demand_2019.tif"
file_path_transport = "/Users/kobabendiks/Desktop/UNI/Bachelor Thesis/Datasets/Demand/transport_electricity_demand_2019.tif"
file_path_transform = "/Users/kobabendiks/Desktop/UNI/Bachelor Thesis/Datasets/Demand/transformationinputs_electricity_demand_2019.tif"
#file_path_nonenergy = "/Users/kobabendiks/Desktop/UNI/Bachelor Thesis/Datasets/Demand/nonenergyuse_electricity_demand_2019.tif"
file_path_total = "/Users/kobabendiks/Desktop/UNI/Bachelor Thesis/Datasets/Demand/total_electricity_demand_2019.tif"
In [5]:
reference_array = np.load('/Users/kobabendiks/Desktop/UNI/Bachelor Thesis/Datasets/Finalised/Arrays/Reference_array.npy')
In [6]:
#Create matrix for each demand type and convert Toe to MWh
import numpy as np
# Read the TIFF file
def read_tiff(file_path):
with rasterio.open(file_path) as src:
data = src.read(1) # Read the first band (assumes single-band TIFF)
profile = src.profile # Metadata profile of the TIFF
return data, profile
# Create a matrix of values from the TIFF file
def create_matrix(file_path):
# Read the TIFF file
data, _ = read_tiff(file_path)
return data
matrix_industry = create_matrix(file_path_industry)
matrix_others = create_matrix(file_path_others)
matrix_transport = create_matrix(file_path_transport)
matrix_transform = create_matrix(file_path_transform)
#matrix_nonenergy = create_matrix(file_path_nonenergy)
matrix_total = create_matrix(file_path_total)
#convert arrays from toe to MWh
matrix_industry_MWh = matrix_industry *11.63
matrix_others_MWh = matrix_others *11.63
matrix_transport_MWh = matrix_transport *11.63
matrix_transform_MWh = matrix_transform *11.63
#matrix_nonenergy_MWh = matrix_nonenergy *11.63
matrix_total_MWh = matrix_total *11.63
# Assuming reference_array and matrix_industry_MWh are NumPy arrays of the same shape
matrix_industry_MWh_St = reference_array.copy()
matrix_transport_MWh_St = reference_array.copy()
matrix_transform_MWh_St = reference_array.copy()
matrix_others_MWh_St = reference_array.copy()
#matrix_nonenergy_MWh_St = reference_array.copy()
matrix_total_MWh_St = reference_array.copy()
# Add matrix_industry_MWh values where they are greater than 0
matrix_industry_MWh_St[matrix_industry_MWh > 0] += matrix_industry_MWh[matrix_industry_MWh > 0]
matrix_others_MWh_St[matrix_others_MWh > 0] += matrix_others_MWh[matrix_others_MWh > 0]
matrix_transport_MWh_St[matrix_transport_MWh > 0] += matrix_transport_MWh[matrix_transport_MWh > 0]
matrix_transform_MWh_St[matrix_transform_MWh > 0] += matrix_transform_MWh[matrix_transform_MWh > 0]
#matrix_nonenergy_MWh_St[matrix_nonenergy_MWh > 0] += matrix_nonenergy_MWh[matrix_nonenergy_MWh > 0]
matrix_total_MWh_St[matrix_total_MWh > 0] += matrix_total_MWh[matrix_total_MWh > 0]
In [39]:
#Display Matrices
def display_matrix (matrix):
colors = [(0, 0, 0)] + [(i / 255, i / 255, i / 255) for i in range(256)]
cmap = LinearSegmentedColormap.from_list("custom_cmap", colors, N=256)
# Plot the entire matrix
plt.figure(figsize=(100, 100))
plt.imshow(matrix, cmap=cmap, vmin=-1, vmax=1) # Adjust the vmin and vmax if necessary
plt.colorbar() # Add a color scale bar
plt.axis('off') # Remove axis for clean display
plt.tight_layout()
plt.show()
display_matrix(matrix_industry_MWh_St)
display_matrix(matrix_others_MWh_St)
display_matrix(matrix_transport_MWh_St)
display_matrix(matrix_transform_MWh_St)
#display_matrix(matrix_nonenergy_MWh)